<?xml version="1.0" encoding="UTF-8"?>
<xsl:stylesheet version="2.0" xmlns:xsl="http://www.w3.org/1999/XSL/Transform"
  xmlns:html="http://www.w3.org/1999/xhtml"
  xmlns:f="livcos.org/ns/xslt/function"
  exclude-result-prefixes="f html">
  
  <xsl:import href="../../common/base.xsl"/>
	
	<xsl:param name="uri"/>
	
	<xsl:template match="/*">
		<xsl:apply-templates select="*"/>
	</xsl:template>
	
	<xsl:template match="*">
		<xsl:apply-templates select="*"/>
	</xsl:template>
	
	<xsl:template match="html:*">
		<xsl:apply-templates select="@href | @src"/>
		<xsl:apply-templates select="*"/>
	</xsl:template>
	
	<xsl:template match="@*">
		<xsl:choose>
			<xsl:when test="starts-with(., 'javascript:')">
				<!-- ignore JavaScript links -->
			</xsl:when>
			<xsl:when test="f:isValidUrl(.)">
				<resource uri="{resolve-uri(f:cut-end(f:cut-end(., '?'), '#'), $uri)}"/>
			</xsl:when>
			<xsl:otherwise>
				<resource uri="{.}" invalid="1"/>
			</xsl:otherwise>
		</xsl:choose>
	</xsl:template>
	
</xsl:stylesheet>
